package com.example.auth.config.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;

import java.io.IOException;

public class OAuth2AuthenticationTokenSerializer extends StdSerializer<OAuth2AuthenticationToken> {

    public OAuth2AuthenticationTokenSerializer() {
        super(OAuth2AuthenticationToken.class);
    }

    @Override
    public void serialize(OAuth2AuthenticationToken value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeStartObject();
        gen.writeStringField("name", value.getName());
        gen.writeStringField("authorizedClientRegistrationId", value.getAuthorizedClientRegistrationId());
        gen.writeObjectField("principal", value.getPrincipal());
        gen.writeObjectField("authorities", value.getAuthorities());
        gen.writeEndObject();
    }
} 